<template name="recharge">
<view class="bgzd">
	<view class="form">
		<view class="form_top">
			<text>客户充值</text>
			<image @click="close" src="/static/img/none_close.png"></image>
		</view>
		<view class="view_input1">
		    <view class="view_input_title1">充值金额:</view>
			<input class="view_input_input1" type="number" @input="give" v-model="pay_money"
			placeholder-class="placeholderClass" placeholder="请输入充值金额"/>
		</view>
		<view class="view_input1">
		    <view class="view_input_title1">赠送代金券:</view>
			<input class="view_input_input1" type="number" @input="give" v-model="give_money"
			placeholder-class="placeholderClass" placeholder="请输入赠送代金券"/>
		</view>
		<view class="view_input1">
		    <view class="view_input_title1">应收金额:</view>
			<input class="view_input_input1" type="number" v-model="money" disabled
			placeholder-class="placeholderClass"/>
		</view>
		<view class="view_input1">
		    <view class="view_input_title1">实收金额:</view>
			<input class="view_input_input1" type="number" v-model="pay_money" disabled
			placeholder-class="placeholderClass"/>
		</view>
		
		<view class="form_footer">
			<button v-if="addRoleTrue" @click="add" class="strue">确认充值</button>
			<button v-else class="sfalse">确认充值</button>
		</view>
	</view>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	name: "recharge",
	//属性
	props:['id'],
	data() {
		return {
			addRoleTrue:true,
			pay_money:'',
			give_money:'',
			money:''
		}
	},
	//组件生命周期
	created:function(e){

	},
	methods:{
		close:function(){
			this.$emit('func',{'type':0,'model':'rechargeShow'})
		},
		give:function(){
			if(this.pay_money){
				var pay = this.pay_money
			}else{
				var pay = 0
			}
			if(this.give_money){
				var give = this.give_money
			}else{
				var give = 0
			}
			this.money = parseFloat(pay) + parseFloat(give)
		},
		add:function(){
			if(!this.pay_money){
				uni.showToast({
					title: '充值金额不能为空!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			var data = {
				member_id:this.id,
				pay_money:this.pay_money,
				give_money:this.give_money,
				oa_id:uni.getStorageSync('oa_id')
			}
			var that = this
			this.addRoleTrue = false
			request({
				url: 'manage/recharge/add',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title: '充值成功!!',
							icon: "none", 
							position:'bottom',
						});
						that.$emit('func',{'type':1,'model':'rechargeShow'})
					}else{
						uni.showToast({
							title: res.data.msg,
							icon: "none", 
							position:'bottom',
						});
					}
				},
			})
		},
	}
}
</script>
<style>
.bgzd{
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	right: 0;
	width: 100%;
	height: 100%;
	background: rgba(0,0,0,0.4);
	z-index:999;
	padding-left:5%;
}
.form{
    padding-top:20rpx;
    width:90%;
    height:40%;
	top:30%;
    /* bottom:0; */
    padding-bottom: 20rpx;
    background:#FFFFFF;
    position: fixed;
    z-index:9999;
	border-radius: 30rpx;
}
.form_top{
	padding-left:2%;
    font-weight:bold;
    font-size:20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width:95%;
}
.form_top image{
    width:35rpx;height:35rpx;
    margin-right: 20rpx;
}
.form_footer{
	margin-left:5%;
    width:90%;
    margin-top:20rpx;
}
.strue{
    width:100%;height:70rpx;line-height:70rpx;
    background:#ff861a;color:#fff;
	border-radius: 40rpx;
}
.sfalse{
    width:100%;height:70rpx;line-height:70rpx;background:#8c8c8c;
    color:#fff;border-radius: 40rpx;
}
</style>